import sqlite3

def create_database():
    conn = sqlite3.connect('database.db')
    c = conn.cursor()

    # 创建品牌表
    c.execute('''CREATE TABLE IF NOT EXISTS brands (
                 id INTEGER PRIMARY KEY AUTOINCREMENT,
                 name TEXT NOT NULL UNIQUE)''')

    # 创建固件表
    c.execute('''CREATE TABLE IF NOT EXISTS firmwares (
                 id INTEGER PRIMARY KEY AUTOINCREMENT,
                 brand_id INTEGER NOT NULL,
                 version TEXT NOT NULL,
                 upload_date TEXT NOT NULL,
                 uploader TEXT NOT NULL,
                 firmware_path TEXT NOT NULL,
                 changelog TEXT NOT NULL,
                 FOREIGN KEY(brand_id) REFERENCES brands(id))''')

    # 插入初始品牌数据
    brands = ['理想', '开迈斯', '特斯拉','吉利','485']
    for brand in brands:
        c.execute("INSERT OR IGNORE INTO brands (name) VALUES (?)", (brand,))

    conn.commit()
    conn.close()

if __name__ == '__main__':
    create_database()